"""
基于socket实现的TCP服务端
"""
import socket

if __name__ == '__main__':
    # 建立socket对象
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # 绑定IP和端口 默认本机IP
    server_socket.bind(('192.168.16.105', 7777))
    # 设置监听
    server_socket.listen(128)
    # 等待客户端连接
    client_socket, ip_port = server_socket.accept()
    print('ip_port = ', ip_port)
    # 接收客户端的消息,解码并设置编码格式
    data = client_socket.recv(1024).decode('gbk')

    print('客户端发送的数据是: ', data)

    # 关闭客户端
    client_socket.close()
    # 关闭服务端
    server_socket.close()
